#include "edmain.h"


// button hwnds here
HWND bSave;
HWND bLoadImg;
HWND bEditImg;
HWND bSaveImg;
HWND bLoad;
HWND bNewArmor;
HWND bNewWeapon;
HWND bNewItem;
HWND bExit;

pxGDI gdi;
cGraphics9 dx;
cSprite9 sprite0;

// WINMAIN ////////////////////////////////////////////////
int WINAPI WinMain(	HINSTANCE hinstance,HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
{
	gInstance = hinstance;

	gdi.setInstance( hinstance ); // MUST BE CALLED AT START OF PROGRAM!!!
	init();

	gWindow = gdi.getWindow();
	// enter main event loop, but this time we use PeekMessage()
	// instead of GetMessage() to retrieve messages
	while(TRUE)
	{
		if (PeekMessage(&gMsg,NULL,0,0,PM_REMOVE))
		{
			if (gMsg.message == WM_QUIT)
				break;

			if(!IsDialogMessage(gNewItemDlg, &gMsg)) 
			{
				if( !IsDialogMessage( gNewArmorDlg, &gMsg))
				{
					if( !IsDialogMessage( gNewWeaponDlg, &gMsg))
					{
						TranslateMessage(&gMsg); // translate any accelerator keys
						DispatchMessage(&gMsg); // Send the messages off
					}
				}
			}
		} // end if

		loop();
	} // end while

	shutdown();
	// return to Windows like this
	return(gMsg.wParam);
}
void init()
{
	gdi.init( "Editor");
	bNewItem = gdi.addButton( "New Item", 10, 20, 100, 25, BUTTON_BS_NEWITEM);
	bNewArmor = gdi.addButton( "New Armor", 10, 60, 100, 25, BUTTON_BS_NEWARMOR);
	bNewWeapon = gdi.addButton( "New Weapon", 10, 100, 100, 25, BUTTON_BS_NEWWEAPON);
	bExit = gdi.addButton( "Exit", 10, 150, 100, 25, BUTTON_BS_EXIT);
	dx.createD3D( gdi.getWindow() );
}

void loop()
{
	doKeys();
	doMouse();

	doInput();
	doLogic();
}

void shutdown()
{
	gdi.destroy();
}

void doInput()
{
}

void doLogic()
{
}

void doKeys()
{
	if( gMsg.message == WM_KEYDOWN)
	{
	}
	if( gMsg.message == WM_KEYDOWN && gMsg.hwnd == gdi.getWindow()) // filter out excess
	{
		if( gMsg.wParam == VK_ESCAPE || gMsg.wParam == 'x' || gMsg.wParam == 'X' )
		{
			shutdown();
			PostQuitMessage(0);
		}

		if( gMsg.wParam == 'a' || gMsg.wParam == 'A' ) // New Armor
		{
			ShowWindow(gWindow, SW_HIDE);
			gNewArmorDlg = CreateDialogParam(gInstance, MAKEINTRESOURCE(IDD_NEWARMOR), 0, NewArmorProc, 0); ShowWindow(gNewArmorDlg, SW_SHOW);
		}

		if ( gMsg.wParam == 'i' || gMsg.wParam == 'I' ) // New Item
		{
			ShowWindow(gWindow, SW_HIDE);
			gNewItemDlg = CreateDialogParam(gInstance, MAKEINTRESOURCE(IDD_NEWITEM), 0, NewItemProc, 0); ShowWindow(gNewItemDlg, SW_SHOW);
		}

		if( gMsg.wParam == 'w' || gMsg.wParam == 'W' ) // New Weapon
		{
			ShowWindow(gWindow, SW_HIDE);
			gNewWeaponDlg = CreateDialogParam(gInstance, MAKEINTRESOURCE(IDD_NEWWEAPON), 0, NewWeaponProc, 0); ShowWindow(gNewWeaponDlg, SW_SHOW);
		}
		if( gMsg.wParam == 'n' || gMsg.wParam == 'N' ) // New item ( could be a weapon, item or armor
		{
			ShowWindow(gWindow, SW_HIDE);
			if( MessageBoxA( gdi.getWindow(), "Is this of type Item?", "Type Item", MB_YESNO ) == IDYES ) // Yes
			{
				gNewItemDlg = CreateDialogParam(gInstance, MAKEINTRESOURCE(IDD_NEWITEM), 0, NewItemProc, 0); ShowWindow(gNewItemDlg, SW_SHOW);
			}
			else if( MessageBoxA( gdi.getWindow(), "Is this of type Weapon?", "TypeItem", MB_YESNO ) == IDYES ) // Yes to weapon
			{
				gNewWeaponDlg = CreateDialogParam(gInstance, MAKEINTRESOURCE(IDD_NEWWEAPON), 0, NewWeaponProc, 0); ShowWindow(gNewWeaponDlg, SW_SHOW);
			}
			else
			{
				if( MessageBoxA( gdi.getWindow(), "Is this of type Armor?", "Type Armor", MB_YESNO ) == IDYES ) // yes to armor
				{
					gNewArmorDlg = CreateDialogParam(gInstance, MAKEINTRESOURCE(IDD_NEWARMOR), 0, NewArmorProc, 0); ShowWindow(gNewArmorDlg, SW_SHOW);
				}
			}
			ShowWindow(gWindow, SW_SHOW);
		}
	}
}

void doMouse()
{

}
